package com.c6906.vdam.magent.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Data
public class ServerData {
    private String hostName;
    private long eventTime;
    //内存
    private static long msgSerialCounter = 0; // 静态变量，所有对象共享，负责自增

    private long msgSerial ;

    private long memTotal;
    private long memAvailable;
    private long memUsed;
    private long memFree;
    private double memUsedPercent;
    //CPU
    private double totalCPUUsage;
    private List<Double> coreUsages;
    //硬盘
    private List<DiskUsage> diskUsages;

    private long serialId;
    public ServerData(){
        this.msgSerial = msgSerialCounter++; // 自增 msgSerial
    }

    public ServerData(String hostname, long eventTime, double totalCPUUsage, long memTotal, long memAvailable, long memUsed, long memFree, double memUsedPercent, List<Double> coreUsages, List<DiskUsage> diskUsages,long serialId) {
        this.hostName = hostname;
        this.eventTime = eventTime;
        this.totalCPUUsage = totalCPUUsage;
        this.memTotal = memTotal;
        this.memAvailable = memAvailable;
        this.memUsed = memUsed;
        this.memFree = memFree;
        this.memUsedPercent = memUsedPercent;
        this.coreUsages = coreUsages;
        this.diskUsages = diskUsages;
        this.serialId = serialId;
        this.msgSerial = msgSerialCounter++; // 自增 msgSerial
    }

    public String toJson() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(this);
    }
}